import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';

interface userDetail {
  uuid: string;
  username: string;
  nickname: string;
}

@Component({
  selector: 'app-account-settings-base',
  templateUrl: './base.component.html',
  styleUrls: ['./base.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SysProfileBaseComponent implements OnInit {
  constructor(private http: _HttpClient, private cdr: ChangeDetectorRef, private msgSrv: NzMessageService) {}
  avatar = '';
  userLoading = true;
  user!: userDetail;

  ngOnInit(): void {
    this.http.get('api/user_detail').subscribe(res => {
      this.userLoading = false;
      this.user = res.data;
      this.cdr.detectChanges();
    });
  }

  save(): boolean {
    this.http.put(`api/user_update`, this.user).subscribe(res => {
      if (res.err_code == 0) {
        this.msgSrv.success(res.msg);
      } else {
        this.msgSrv.error(res.msg);
      }
    });
    return true;
  }
}
